<template>
  <div class="gl_contentBox gl_heightFull">
    <div class="demo-input-suffix gl_searchBox">
      <el-row :gutter="20">
        <el-col :span="4">
          <p>提交机构</p>
          <el-input v-model="qo.OrganizationUnitName" placeholder="请输入机构名称" size="mini" clearable @change="getPageList()" />
        </el-col>
        <el-col :span="4">
          <p>考生姓名</p>
          <el-input v-model="qo.StudentName" placeholder="请输入考生姓名" size="mini" clearable @change="getPageList()" />
        </el-col>
        <el-col :span="4">
          <p>证件号</p>
          <el-input v-model="qo.IdCardNumber" placeholder="请输入证件号" size="mini" clearable @change="getPageList()" />
        </el-col>
        <el-col :span="4">
          <p>考试结果</p>
          <el-select v-model="qo.ScoreStatusCode" size="mini" placeholder="请选择考试结果" filterable @change="getPageList()">
            <el-option label="全部" :value="null" />
            <el-option v-for="jtem in dict.scoreStatus" :key="jtem.code" :value="jtem.code" :label="jtem.value" />
          </el-select>
        </el-col>
        <el-col :span="8" class="search_btn" align="left">
          <!-- 查询按钮 -->
          <el-button type="primary" size="mini" @click="getPageList()">筛选</el-button>
          <!-- 重置按钮 -->
          <el-button type="warning" size="mini" @click="clickReset()">{{ $t('button.Reset') }}</el-button>
        </el-col>
      </el-row>
    </div>
    <el-table v-loading="tableLoading" :data="tableData" class="gl_table_noBorder gl_mt_15" size="mini">
      <el-table-column label="序号" type="index" width="50" />
      <el-table-column label="姓名" align="center" width="54">
        <template slot-scope="{row}">
          <!-- <img class="roodsPhoto" :src="getStaticFileUrl(row.imagePath)" alt=""> -->
          <PersonalImage :imgurl="row.imagePath" imgheight="60px" />
        </template>
      </el-table-column>
      <el-table-column label="" min-width="100">
        <template slot-scope="{row}">
          {{ row.studentName || '--' }}
        </template>
      </el-table-column>
      <el-table-column label="证件号" prop="idCardNumber" min-width="120" />
      <el-table-column label="联系方式" prop="phoneNumber" min-width="100" />
      <el-table-column label="申报级别" :min-width="80">
        <template slot-scope="{row}">
          <span v-for="(item, index) in row.duanExamStudentDuans" :key="item.duanId">
            {{ item.duan ? item.duan.name : '' }} {{ row.duanExamStudentDuans.length - 1 === index ? '': '/' }}
          </span>
        </template>
      </el-table-column>
      <el-table-column label="教练" prop="coachName" :min-width="80" />
      <el-table-column label="提交机构" prop="organizationUnitName" :min-width="120" />
      <el-table-column label="成绩" prop="score" />
      <el-table-column label="考官" prop="duanExamOfficialName" min-width="65" />
      <el-table-column label="考试结果" prop="scoreStatus.name" min-width="80" />
      <el-table-column label="证书编号" prop="certificateNumber" min-width="120" />
    </el-table>
    <el-row class="gl_pt_15" style="text-align: right;">
      <el-pagination
        :current-page="qo.Page"
        :page-size="qo.MaxResultCount"
        :total="total"
        layout="total,sizes,prev,pager,next,jumper"
        :page-sizes="[10, 20, 30, 40]"
        @size-change="sizeChange"
        @current-change="pageIndexChange"
      />
    </el-row>
  </div>
</template>

<script>
import { mapState, mapActions } from 'vuex';
import PersonalImage from '@/components/PersonalImage/index';
import { Api_GET_ClubBranchBranchDuanStudentsBranchIdQO } from '@/lib/form/hall/swaggerForm';
import { api_GET_ClubBranchBranchDuanStudentsBranchId } from '@/extend/api/hallswaggerApi/app';
export default {
  components: {
    PersonalImage
  },
  data() {
    return {
      qo: new Api_GET_ClubBranchBranchDuanStudentsBranchIdQO(),
      campusExamId: '',
      branchId: '',
      tableLoading: false,
      total: 0,
      tableData: []
    };
  },
  computed: {
    ...mapState({
      dict: state => state.dict.dict
    })
  },
  created() {
    this.campusExamId = this.$route.query.campusExamId || this.$route.params.campusExamId || '';
    this.branchId = this.$route.query.branchid || this.$route.params.branchid || '';
    this.getDict();
    this.getPageList();
  },
  methods: {
    // 若没有字典信息，外部可直接调用方法获取字典数据
    ...mapActions({ getDict: 'dict/getDict' }),
    // 获取参报名单
    getPageList(page) {
      this.qo.Page = page || 1;
      this.qo.SkipCount = (this.qo.Page - 1) * this.qo.MaxResultCount;
      this.qo.DuanExamId = this.campusExamId;
      this.qo.IncludeTeachingMode = true;
      this.qo.IncludeLessonPeriod = true;
      this.qo.IncludeDuanExamRequestDuans = true;
      this.qo.IncludeRegisterStudent = true;
      this.qo.IncludeScoreStatus = true;
      this.qo.Sorting = 'creationTime DESC';
      this.tableLoading = true;
      api_GET_ClubBranchBranchDuanStudentsBranchId(this.branchId, this.qo).then(res => {
        this.tableLoading = false;
        this.tableData = res.items;
        this.total = res.totalCount;
      }, error => {
        this.tableLoading = false;
        const _msg = error.error.message || error.message;
        this.$message({ type: 'error', message: _msg });
      });
    },
    // 获取静态文件
    getStaticFileUrl(relativeUrl) {
      if (!relativeUrl) return '';
      return WEB_CONFIG.VUE_APP_STATIC_FILE_RUL + relativeUrl;
    },
    clickReset() {
      this.qo = new Api_GET_ClubBranchBranchDuanStudentsBranchIdQO();
      this.getPageList();
    },
    errorPhoto() {
      const img = event.srcElement;
      img.src = this.defaultImg;
      img.onerror = null;
    },
    // 分页
    sizeChange(MaxResultCount) {
      this.qo.MaxResultCount = MaxResultCount;
      this.getPageList();
    },
    pageIndexChange(currentPage) {
      this.getPageList(currentPage);
    }
  }
};
</script>
<style lang="scss" scoped>
  .roodsPhoto{
    width: 60px;
    height: 60px;
    border-radius: 6px;
    vertical-align: middle;
  }
</style>
